package com.lagou.rabbitmq.consumerconfirm;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Producer {

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        //指定协议 amqp://
        //指定用户名 root
        //指定密码 123456
        //指定host 47.115.74.219
        //指定端口号 5672
        //指定虚拟主机 %2f
        factory.setUri("amqp://root:123456@47.115.74.219:5672/%2f");

        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();

        //声明队列
        //第一个参数 交换器名称
        //第二个参数 是否持久化
        //第三个参数 是否排他
        //第四个参数 是否自动删除
        //第五个参数 交换器属性信息
        channel.queueDeclare("queue.ca",false ,false,false,null);
        channel.exchangeDeclare("ex.ca",BuiltinExchangeType.DIRECT,false,false,null);
        channel.queueBind("queue.ca","ex.ca","key.ca");

        for(int i = 0;i < 5;i++){
            channel.basicPublish("ex.ca","key.ca",null,"hello".getBytes(StandardCharsets.UTF_8));
        }


        channel.close();
        connection.close();
    }

}
